// page_two/suojsp/suojsp.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: '索记索票',
    page: 1,
    // suojsp: [
    //   {
    //     id: 1,
    //     time: '2021-06-26',
    //     name: '12345',
    //     sbtime: '2021-06-26 08:54:59',
    //     fyitem: ['垃圾费']
    //   },
    //   {
    //     id: 2,
    //     time: '2020-03-25',
    //     name: '卡卡',
    //     sbtime: '2021-05-26 17:33:59',
    //     fyitem: ['垃圾费', '公摊电费']
    //   },
    //   {
    //     id: 3,
    //     time: '2021-05-21',
    //     name: '王者',
    //     sbtime: '2021-06-26 18:49:43',
    //     fyitem: ['住宅管理费', '垃圾费']
    //   },
    //   {
    //     id: 4,
    //     time: '2021-05-20',
    //     name: '11',
    //     sbtime: '2021-05-20 15:12:10',
    //     fyitem: ['住宅管理费']
    //   }
    // ],
    suojsp: [],
     // 搜素
     keywordsone:"",
     start: '开始时间',
     endtime: '结束时间',
     begintime: '',
     endtimes: '',
  },


  // 搜索

  
  keywordsone(e) {
    console.log(e)
    var key = e.detail.value
    this.setData({
      keywordsone: key
    })


    this.getsjspList()
  
  },
  bindkaishi(e) {
    this.setData({
      start: e.detail.value,
      begintime: e.detail.value,
    })
    this.getsjspList()

  },
  bindjieshu(e) {
    if (e.detail.value < this.data.begintime) {
      wx.showToast({
        title: '结束时间不能小于开始时间',
        icon: 'none'
      })
    } else {
      this.setData({
        endtime: e.detail.value,
        endtimes: e.detail.value,
      })
      this.getsjspList()
    }
  },
  chonzghia(){
    this.setData({
      keywordsone: '',
      endtimes: '',
      start: '开始时间',
    endtime: '结束时间',
      begintime:'',
    })
    this.getsjspList()

  },


  // 删除
  shanchu(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          that.dele(id)
        } else {
          console.log("取消")
        }
      }
    })
  },
  dele(id) {
    let that = this
    this.myRequest(yuming + 'Besall/TicketsReportDel', {
      id: id,
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        that.getsjspList()
      }
    })
  },
  jia() {
    wx.navigateTo({
      url: '/page_two/suojadd/suojadd',
    })
  },
  // 点击放大
  fangdas(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  getsjspList() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let that = this
    this.myRequest(yuming + 'Besall/TicketsReportList', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page,
      keywords:this.data.keywordsone,
      start_time:this.data.begintime,
      end_time:this.data.endtimes
    }, "POST").then(res => {
      wx.hideLoading()
      this.setData({
        suojsp: res.data.data
      })
      for (let i = 0; i < that.data.suojsp.length; i++) {
        that.data.suojsp[i].open = false;
        let pname = that.data.suojsp[i].pricename
        pname = pname.slice(0, pname.length - 1);
        that.data.suojsp[i].pricename = pname.split(',');
      }
      console.log(that.data.suojsp)
    })
  },
  kindToggle(e) {
    const id = e.currentTarget.id
    const suojsp = this.data.suojsp
    for (let i = 0, len = suojsp.length; i < len; ++i) {
      if (suojsp[i].id == id) {
        suojsp[i].open = !suojsp[i].open
      } else {
        suojsp[i].open = false
      }
    }
    this.setData({
      suojsp
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      shopType: options.shopType,
      title: options.title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getsjspList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})